package com.nd.qa.shareplate.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * FTP文件的上传下载
 * @author huangjian
 * @createDate 2015-12-22
 * @version V1.0
 */
public class FTPFileUtil {

	/**
	 * http下载
	 * 
	 * */  
	public static boolean httpDownload(String httpUrl,String saveFile){  
	       // 下载网络文件  
	       int bytesum = 0;  
	       int byteread = 0;  
	       URL url = null;  
	    try {  
	        url = new URL(httpUrl);
	        URLConnection conn = url.openConnection();  
            InputStream inStream = conn.getInputStream();  
            FileOutputStream fs = new FileOutputStream(saveFile);  
  
            byte[] buffer = new byte[1204];  
            while ((byteread = inStream.read(buffer)) != -1) {  
               bytesum += byteread;  
               System.out.println(bytesum);  
               fs.write(buffer, 0, byteread);  
            }
            inStream.close();
            fs.flush();
            fs.close();
            return true;  
	    } catch (MalformedURLException e1) {  
	        e1.printStackTrace();  
	        return false;  
	    }  catch (FileNotFoundException e) {  
	           e.printStackTrace();  
	           return false;  
        } catch (IOException e) {  
           e.printStackTrace();  
           return false;  
        }   
	}  
}
